package com.wcr.edu.info.manager.dao;

import com.wcr.edu.info.manager.domain.Student;

public class StudentDao {
    static Student[] schar = new Student[5];

    //添加方法(库管)
    public boolean addDao(Student student) {
        int index = -1;
        for (int i = 0; i < schar.length; i++) {
            Student student1 = schar[i];
            //把遍历的值赋给学生类对象
            if (student1 == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            System.out.println("空间不足");
            return false;
        } else {
            schar[index] = student;

        }
        return true;
    }

    //查看方法(库管)=
    public Student[] ckStudent() {
        return schar;
    }

    //修改方法(库管)
    public boolean xiugai(String newid, Student newstudent) {
        boolean b = false;
        int index = jianChaId(newid);
        schar[index] = newstudent;
        b = true;

        return b;

    }

    //删除学生(库管)
    public void shanChuId(String shanChuId) {
        int index = jianChaId(shanChuId);
        schar[index] = null;

    }


    //检查ID方法
    public int jianChaId(String Id) {
        int index = -1;
        for (int i = 0; i < schar.length; i++) {
            Student stu = schar[i];
            if (stu != null && stu.getId().equals(Id)) {
                index = i;
            }
        }
        return index;
    }

}
